{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Range built-in-function.ipynb",
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/Tanu-N-Prabhu/Python/blob/master/Range_built_in_function.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "piQxd_rde0qI",
        "colab_type": "text"
      },
      "source": [
        "# Python range() built-in-function"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jKR-Zhy4e2y3",
        "colab_type": "text"
      },
      "source": [
        "Let us understand the basics of range() function in python.\n",
        "\n",
        "![alt text](https://cdn-images-1.medium.com/max/1200/1*uCoxqbJcEkjyml4j4C7_dw.png)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "I91Tnx_je6k7",
        "colab_type": "text"
      },
      "source": [
        "Now let us understand the concept of range function() in python, below shown are the concepts along with examples that will help you guys to understand the range() in a clear way.\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qSOoKFyoe9rw",
        "colab_type": "text"
      },
      "source": [
        "## Definition\n",
        "\n",
        "The range() function is a built-in-function used in python, it is used to generate a sequence of numbers. If the user wants to generate a sequence of numbers given the starting and the ending values then they can give these values to the parameter of the range() function. The range() function will then generate a sequence of numbers according to the user's requirement.\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-jI05C1BfFv7",
        "colab_type": "text"
      },
      "source": [
        "## Syntax\n",
        "\n",
        "The syntax of range() function is shown below:\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "range(start, stop, step)\n",
        "```\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1KVT12FJfKhB",
        "colab_type": "text"
      },
      "source": [
        "## Parameters\n",
        "\n",
        "There are three parameters inside the range(): start, stop, and step. When you think about these three-parameters, these resemble a real-life scenario such as you need to set the boundaries and then walk with defined steps.\n",
        "\n",
        "\n",
        "\n",
        "```\n",
        "Start: Optional - An integer number that specifies where to start     (Default value is 0)\n",
        "Stop: Required - An integer number that specifies where to stop.\n",
        "Step: Optional - An integer number that specifies how much to increment the number (Default value is 1)\n",
        "\n",
        "```\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "5PqbjR4xfTlh",
        "colab_type": "text"
      },
      "source": [
        "## Return Values\n",
        "\n",
        "The return value of the range function is a sequence of numbers depending upon the parameters defined.\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wBHwbWIKfdz1",
        "colab_type": "text"
      },
      "source": [
        "## Examples\n",
        "\n",
        "**1. Let us see what happens when we just print the range function with the value 10.**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "c0WDY9B9fg5j",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "a090a8de-aaa6-4e88-d84c-038025874b49"
      },
      "source": [
        "x = range(10)\n",
        "print(x)"
      ],
      "execution_count": 42,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "range(0, 10)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "M3aIejqVfjwF",
        "colab_type": "text"
      },
      "source": [
        "As seen above the value 10 indicates the stop value for the range function and the 0 value is by default added as the starting value.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DTC0swZKfo1D",
        "colab_type": "text"
      },
      "source": [
        "**2. Let us see what happens when we put the range function in a for loop.**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "I7wf8bZKfjNf",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 191
        },
        "outputId": "6cbd9671-7f37-4bb3-8abb-3f3d3be414f9"
      },
      "source": [
        "x = range(10)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 44,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "0\n",
            "1\n",
            "2\n",
            "3\n",
            "4\n",
            "5\n",
            "6\n",
            "7\n",
            "8\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "IciUEO43fxeV",
        "colab_type": "text"
      },
      "source": [
        "Now as seen above we can get the values from 0 to 10 but excluding 10 because the stop value of the range function always returns the value -1. Hence the values 0–10.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xeDAkeugfzLO",
        "colab_type": "text"
      },
      "source": [
        "**3. Let us see what happens that we give the start and the stop value to the range function.**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rH8UvaM2f1Hq",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 173
        },
        "outputId": "e6cfde7e-fb73-4250-bc69-3df98a02b184"
      },
      "source": [
        "x = range(1, 10)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 45,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1\n",
            "2\n",
            "3\n",
            "4\n",
            "5\n",
            "6\n",
            "7\n",
            "8\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Bi3-UfWVf4o2",
        "colab_type": "text"
      },
      "source": [
        "As seen above its prints the values from 1–9 because the start value is defined as 1.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xp__pbt3f8kN",
        "colab_type": "text"
      },
      "source": [
        "**4. Let us see what happens when we give the step value to the range function.**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "u_2d_jEDf-1U",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 104
        },
        "outputId": "485b9419-a0c4-46ec-c3cd-701a55d17c2b"
      },
      "source": [
        "x = range(1, 10, 2)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 46,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1\n",
            "3\n",
            "5\n",
            "7\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "r5m300IggCtT",
        "colab_type": "text"
      },
      "source": [
        "As seen above the step is used to increment the numbers, in this case, the step is 2 so the number is incremented by 2.\n",
        "\n",
        "In general, think this way the range function is like a real-life scenario:\n",
        "\n",
        "\n",
        "\n",
        "\n",
        "*   You start to walk - start\n",
        "*   You make your steps (footsteps) - step\n",
        "*   You stop to walk because you have reached your destination - stop.\n",
        "\n",
        "\n",
        "\n",
        "Even though you don't declare the step variable in this case you will take one step at a time, Obviously, nobody takes two steps at a time.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6KeiQq5SgRr5",
        "colab_type": "text"
      },
      "source": [
        "## The range function is of type class\n",
        "\n",
        "Yes, the range function is a class because when you check the type of the range function using type() then you get the answer."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "uwscUnshgRKe",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        },
        "outputId": "ea5ca794-fb92-4a41-de71-fcff3a021ecb"
      },
      "source": [
        "x = range(10)\n",
        "print(type(x))"
      ],
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<class 'range'>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Xv659V7HgYGQ",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uVWd7RCYgYpG",
        "colab_type": "text"
      },
      "source": [
        "## Don't pass any float values inside the range function.\n",
        "\n",
        "The range function does not work for floating-point values, because according to the range function the floating object cannot be interpreted as an integer. Hence make it a common rule that always specifies integer values inside a range function."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "HMutYClBga_O",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 201
        },
        "outputId": "6643d543-eb84-449a-82df-1832e03a4dbc"
      },
      "source": [
        "x = range(10.0, 100.5)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 48,
      "outputs": [
        {
          "output_type": "error",
          "ename": "TypeError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-48-55e80efae649>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10.0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100.5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mTypeError\u001b[0m: 'float' object cannot be interpreted as an integer"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_MMqsAtegdvz",
        "colab_type": "text"
      },
      "source": [
        "If at all you need to solve it you can typecast it to integers, in this case"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "MOr24F_CgeNl",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "52dedfb6-8908-46a3-dd03-6f9099795549"
      },
      "source": [
        "x = range(int(10.0), int(100.5))\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 49,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "10\n",
            "11\n",
            "12\n",
            "13\n",
            "14\n",
            "15\n",
            "16\n",
            "17\n",
            "18\n",
            "19\n",
            "20\n",
            "21\n",
            "22\n",
            "23\n",
            "24\n",
            "25\n",
            "26\n",
            "27\n",
            "28\n",
            "29\n",
            "30\n",
            "31\n",
            "32\n",
            "33\n",
            "34\n",
            "35\n",
            "36\n",
            "37\n",
            "38\n",
            "39\n",
            "40\n",
            "41\n",
            "42\n",
            "43\n",
            "44\n",
            "45\n",
            "46\n",
            "47\n",
            "48\n",
            "49\n",
            "50\n",
            "51\n",
            "52\n",
            "53\n",
            "54\n",
            "55\n",
            "56\n",
            "57\n",
            "58\n",
            "59\n",
            "60\n",
            "61\n",
            "62\n",
            "63\n",
            "64\n",
            "65\n",
            "66\n",
            "67\n",
            "68\n",
            "69\n",
            "70\n",
            "71\n",
            "72\n",
            "73\n",
            "74\n",
            "75\n",
            "76\n",
            "77\n",
            "78\n",
            "79\n",
            "80\n",
            "81\n",
            "82\n",
            "83\n",
            "84\n",
            "85\n",
            "86\n",
            "87\n",
            "88\n",
            "89\n",
            "90\n",
            "91\n",
            "92\n",
            "93\n",
            "94\n",
            "95\n",
            "96\n",
            "97\n",
            "98\n",
            "99\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fqS0Yf8RgiT_",
        "colab_type": "text"
      },
      "source": [
        "To support this context I was doing some research on StackOverflow and then I got to see a problem there which was stated as \"**I want to loop from 0 to 100 but with a step of 1/2**\" now this is not a simple problem, because the above concept applies for this so you need to use some logic, now I have used some sort of my logic to solve this problem as shown below:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "WbsHvyqZgjx6",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "outputId": "4babb7e6-3a53-45b1-ba0d-88ecf09f6393"
      },
      "source": [
        "x = range(0, 100 * 2)\n",
        "for i in x:\n",
        "    print(i * 0.5)"
      ],
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "0.0\n",
            "0.5\n",
            "1.0\n",
            "1.5\n",
            "2.0\n",
            "2.5\n",
            "3.0\n",
            "3.5\n",
            "4.0\n",
            "4.5\n",
            "5.0\n",
            "5.5\n",
            "6.0\n",
            "6.5\n",
            "7.0\n",
            "7.5\n",
            "8.0\n",
            "8.5\n",
            "9.0\n",
            "9.5\n",
            "10.0\n",
            "10.5\n",
            "11.0\n",
            "11.5\n",
            "12.0\n",
            "12.5\n",
            "13.0\n",
            "13.5\n",
            "14.0\n",
            "14.5\n",
            "15.0\n",
            "15.5\n",
            "16.0\n",
            "16.5\n",
            "17.0\n",
            "17.5\n",
            "18.0\n",
            "18.5\n",
            "19.0\n",
            "19.5\n",
            "20.0\n",
            "20.5\n",
            "21.0\n",
            "21.5\n",
            "22.0\n",
            "22.5\n",
            "23.0\n",
            "23.5\n",
            "24.0\n",
            "24.5\n",
            "25.0\n",
            "25.5\n",
            "26.0\n",
            "26.5\n",
            "27.0\n",
            "27.5\n",
            "28.0\n",
            "28.5\n",
            "29.0\n",
            "29.5\n",
            "30.0\n",
            "30.5\n",
            "31.0\n",
            "31.5\n",
            "32.0\n",
            "32.5\n",
            "33.0\n",
            "33.5\n",
            "34.0\n",
            "34.5\n",
            "35.0\n",
            "35.5\n",
            "36.0\n",
            "36.5\n",
            "37.0\n",
            "37.5\n",
            "38.0\n",
            "38.5\n",
            "39.0\n",
            "39.5\n",
            "40.0\n",
            "40.5\n",
            "41.0\n",
            "41.5\n",
            "42.0\n",
            "42.5\n",
            "43.0\n",
            "43.5\n",
            "44.0\n",
            "44.5\n",
            "45.0\n",
            "45.5\n",
            "46.0\n",
            "46.5\n",
            "47.0\n",
            "47.5\n",
            "48.0\n",
            "48.5\n",
            "49.0\n",
            "49.5\n",
            "50.0\n",
            "50.5\n",
            "51.0\n",
            "51.5\n",
            "52.0\n",
            "52.5\n",
            "53.0\n",
            "53.5\n",
            "54.0\n",
            "54.5\n",
            "55.0\n",
            "55.5\n",
            "56.0\n",
            "56.5\n",
            "57.0\n",
            "57.5\n",
            "58.0\n",
            "58.5\n",
            "59.0\n",
            "59.5\n",
            "60.0\n",
            "60.5\n",
            "61.0\n",
            "61.5\n",
            "62.0\n",
            "62.5\n",
            "63.0\n",
            "63.5\n",
            "64.0\n",
            "64.5\n",
            "65.0\n",
            "65.5\n",
            "66.0\n",
            "66.5\n",
            "67.0\n",
            "67.5\n",
            "68.0\n",
            "68.5\n",
            "69.0\n",
            "69.5\n",
            "70.0\n",
            "70.5\n",
            "71.0\n",
            "71.5\n",
            "72.0\n",
            "72.5\n",
            "73.0\n",
            "73.5\n",
            "74.0\n",
            "74.5\n",
            "75.0\n",
            "75.5\n",
            "76.0\n",
            "76.5\n",
            "77.0\n",
            "77.5\n",
            "78.0\n",
            "78.5\n",
            "79.0\n",
            "79.5\n",
            "80.0\n",
            "80.5\n",
            "81.0\n",
            "81.5\n",
            "82.0\n",
            "82.5\n",
            "83.0\n",
            "83.5\n",
            "84.0\n",
            "84.5\n",
            "85.0\n",
            "85.5\n",
            "86.0\n",
            "86.5\n",
            "87.0\n",
            "87.5\n",
            "88.0\n",
            "88.5\n",
            "89.0\n",
            "89.5\n",
            "90.0\n",
            "90.5\n",
            "91.0\n",
            "91.5\n",
            "92.0\n",
            "92.5\n",
            "93.0\n",
            "93.5\n",
            "94.0\n",
            "94.5\n",
            "95.0\n",
            "95.5\n",
            "96.0\n",
            "96.5\n",
            "97.0\n",
            "97.5\n",
            "98.0\n",
            "98.5\n",
            "99.0\n",
            "99.5\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F7w_fSt5gseH",
        "colab_type": "text"
      },
      "source": [
        "You are free to solve the above problem with your logic and provide the solution in the comment section below.\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8q3QFPpSgue4",
        "colab_type": "text"
      },
      "source": [
        "## xrange function\n",
        "\n",
        "This is also a built-in-function in python which also works in the same way as the range() I think, when I tried executing it I got a weird error:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "QSNX558dgxvX",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 201
        },
        "outputId": "04df503a-dcf6-4888-e061-f1d8bc635150"
      },
      "source": [
        "x = xrange(1, 5)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 51,
      "outputs": [
        {
          "output_type": "error",
          "ename": "NameError",
          "evalue": "ignored",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-51-969120b3b060>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mx\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mxrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      2\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mx\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      3\u001b[0m     \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mNameError\u001b[0m: name 'xrange' is not defined"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "fBRvWZcyg1Co",
        "colab_type": "text"
      },
      "source": [
        "Then after quite a research, I came to know that the xrange is the incremental version of range according to stack overflow. One of them said that Python2 uses xrange() and Python3 uses range, so you don' t have to worry about it.\n",
        "\n",
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "q7B_tQbdg3fT",
        "colab_type": "text"
      },
      "source": [
        "## Range functions can also be used on lists\n",
        "\n",
        "The range functions can also be used on the python list. An easy way to do this is as shown below:"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "rNeBqKz2g6m1",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 69
        },
        "outputId": "a4c7b9d7-1393-40f4-9184-738743d687ec"
      },
      "source": [
        "names = ['India', 'Canada', 'United States', 'United Kingdom']\n",
        "for i in range(1, len(names)):\n",
        "    print(names[i])"
      ],
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "Canada\n",
            "United States\n",
            "United Kingdom\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6Z1JjNaFg8ia",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "-0wpMry8g-Fr",
        "colab_type": "text"
      },
      "source": [
        "## Incrementing and decrementing using the range function\n",
        "\n",
        "\n",
        "I think by this time you guys know how to do this. But anyways I would provide the solution to this problem. You got to just play with the **step parameter** in this case.\n",
        "\n",
        "**Incrementing**\n"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "XutJzzfqhM_r",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 104
        },
        "outputId": "0461649e-f569-4dfa-b359-223b051ee9c8"
      },
      "source": [
        "x = range(1, 10, 2)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 53,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "1\n",
            "3\n",
            "5\n",
            "7\n",
            "9\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "2CVOwINshnHa",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "m-zZyOsghP0n",
        "colab_type": "text"
      },
      "source": [
        "**Decrementing**"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "yMtoQ83xhQwE",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 104
        },
        "outputId": "e05c0b33-9491-42b5-968c-4415e963fe8a"
      },
      "source": [
        "x = range(10, 1, -2)\n",
        "for i in x:\n",
        "    print(i)"
      ],
      "execution_count": 54,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "10\n",
            "8\n",
            "6\n",
            "4\n",
            "2\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BzyEi7fBhTX6",
        "colab_type": "text"
      },
      "source": [
        "\n",
        "\n",
        "---\n",
        "\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mT0SxMLzhT8E",
        "colab_type": "text"
      },
      "source": [
        "This is all you need to know about the range function in python, if you need read more about the official documentation about the range function then I recommend you to read Python's official guide:\n",
        "\n",
        "[Python Range function](https://docs.python.org/3/library/functions.html#func-range)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cpEyiUNVhfLV",
        "colab_type": "text"
      },
      "source": [
        "Thank you guys for reading this short tutorial, I hope you enjoyed it, let me know about your opinion, and if you have any doubt then the comment section is all yours.\n",
        "\n",
        "# Author: Tanu Nanda Prabhu\n",
        "\n",
        "---\n",
        "\n"
      ]
    }
  ]
}